Repository navigation
Add a replace option to useRouteQuery - #11
Merged
Merged
Conversation
setQuery and setQueryParam always called router.push(), so every filter update added a browser-history entry and the back button walked through filter states instead of leaving the page. Passing replace: true now routes both setters through router.replace() instead, keeping the default push behavior for existing callers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
useRouteQuery'ssetQueryandsetQueryParamalways callrouter.push(). When the composable is used to keep UI filters (search terms, pagination, sort order) in the URL, every keystroke or filter change adds a new browser-history entry. The back button then walks back through a sequence of filter states instead of leaving the page, which is not what users expect from filter UI.Change
Adds an optional
replace?: booleanto the composable's options. When set, bothsetQueryandsetQueryParamcallrouter.replace()instead ofrouter.push(), updating the current history entry in place rather than pushing a new one. The default remainspush, so this is fully backwards compatible — existing callers see no behavior change.Downstream use case
Writing list filters into the URL (search, category, sort, page) without polluting browser history — each filter change updates the query string but the back button still takes the user out of the filtered list rather than through every intermediate filter state.
Testing
replacepath for bothsetQueryandsetQueryParam.npm run type-check— passesnpm run lint— passesoxfmt --check— all files correctly formattednpm test— 736/736 tests passing (46 files)npm run build— builds successfully